package com.bridgetree.jubaocrm.ui.groups;

import java.util.ArrayList;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.BaseAdapter;
import android.widget.ListView;
import android.widget.TextView;

import com.bridgetree.jubaocrm.R;
import com.bridgetree.jubaocrm.util.Groups;

/**
 *小组主页
 */
public class GroupMainListActivity extends Activity {
	private final String TAG ="GroupMainListActivity";
	private Context mContext;
	private ListView group_main_list = null;
	private GroupMainListAdapter mGroupMainListAdapter = null;
	private Groups mGroups;
	private ArrayList<String> proInfoListData = null;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.group_main_list);
		mContext=this;

		Intent intent = getIntent();
		if (intent == null) {
			Log.e(TAG, "intent is null");
			return;
		}

		TextView xm_bi_tv_title =(TextView)findViewById(R.id.xm_bi_tv_title);
		if(intent.getExtras()!=null){
			mGroups = (Groups)intent.getExtras().getSerializable("groupsMain");
			xm_bi_tv_title.setText(mGroups.getGroup_name());
		}

		findViewById(R.id.xm_bi_RelativeLayout_back).setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				finish();
			}
		});

		group_main_list = (ListView) findViewById(R.id.group_main_list);
		proInfoListData = new ArrayList<String>();
			proInfoListData.add("组内公告");
			proInfoListData.add("小组成员");
			proInfoListData.add("新报备项目");
			proInfoListData.add("项目列表");
			proInfoListData.add("项目公海");
			proInfoListData.add("客户");
			
			mGroupMainListAdapter = new GroupMainListAdapter(mContext, proInfoListData);
			group_main_list.setAdapter(mGroupMainListAdapter);
			group_main_list.setOnItemClickListener(new OnItemClickListener() {

				@Override
				public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
						long arg3) {
					Intent intent=null;
					Bundle bundle=null;
					// TODO Auto-generated method stub
					switch (arg2) {
					case 0:
						intent = new Intent(mContext, GroupsAnnouncementActivity.class);
						bundle = new Bundle();
						bundle.putSerializable("groupsMain", mGroups);
						intent.putExtras(bundle);
						startActivity(intent);
						break;
					case 1:
						intent = new Intent(mContext, GroupsMemberActivity.class);
						bundle = new Bundle();
						bundle.putSerializable("groupsMain", mGroups);
						intent.putExtras(bundle);
						startActivity(intent);
						break;
					case 2:
						intent = new Intent(mContext, GroupsNewBaoBeiChildActivity.class);
						bundle = new Bundle();
						bundle.putSerializable("groupsMain", mGroups);
						intent.putExtras(bundle);
						startActivity(intent);
						break;
					case 3:
						intent = new Intent(mContext, GroupsProjectListActivity.class);
						bundle = new Bundle();
						bundle.putSerializable("groupsMain", mGroups);
						intent.putExtras(bundle);
						startActivity(intent);
						break;
					case 4:
						intent = new Intent(mContext, GroupsHaiListActivity.class);
						bundle = new Bundle();
						bundle.putSerializable("groupsMain", mGroups);
						intent.putExtras(bundle);
						startActivity(intent);
						break;
					case 5:
						intent = new Intent(mContext, GroupsContactListActivity.class);
						bundle = new Bundle();
						bundle.putSerializable("groupsMain", mGroups);
						intent.putExtras(bundle);
						startActivity(intent);
						break;
					}
				}


			});
	}
	
	class GroupMainListAdapter extends BaseAdapter {
		private ArrayList<String> DrugstoreDataList = null;
		private LayoutInflater listContainer; // 视图容器

		public final class ListItemView { // 自定义控件集合
			public TextView xm_12_item_tv;
		}

		public GroupMainListAdapter(Context mContext, ArrayList<String> data) {
			this.DrugstoreDataList = data;
			listContainer = (LayoutInflater) mContext
					.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		}

		@Override
		public int getCount() {
			if (DrugstoreDataList != null) {
				return DrugstoreDataList.size();
			}
			return 0;
		}

		@Override
		public Object getItem(int position) {
			// TODO Auto-generated method stub
			return DrugstoreDataList.get(position);
		}

		@Override
		public long getItemId(int position) {
			// TODO Auto-generated method stub
			return position;
		}

		@Override
		public View getView(int position, View convertView, ViewGroup parent) {
			// TODO Auto-generated method stub
			ListItemView listItemView = null;
			if (convertView == null) {
				listItemView = new ListItemView();
				// 获取list_item布局文件的视图
				convertView = listContainer.inflate(R.layout.xm_12_item, null);
				// 获取控件对象
				listItemView.xm_12_item_tv = (TextView) convertView.findViewById(R.id.xm_12_item_tv);
				// 设置控件集到convertView
				convertView.setTag(listItemView);
			} else {
				listItemView = (ListItemView) convertView.getTag();
			}
			// 设置文字和图片
			listItemView.xm_12_item_tv.setText((String) DrugstoreDataList
					.get(position));
			// listItemView.RelativeLayout_drugstorelist.setOnClickListener(new
			// OnClickListener() {
			//
			// @Override
			// public void onClick(View v) {
			// // TODO Auto-generated method stub
			// mContext.startActivity(new Intent(mContext,
			// DrugStoreDetailsActivity.class));
			// }
			// });
			return convertView;
		}

}
}
